﻿using System;
using System.Collections.Generic;
using System.Text;
using YouHP.Utility;
using YouHP.Model;
using YouHP.BLL;

namespace YouHP.Pages.Admin
{
    public class AddTreatment : YouHP.Pages.BasePage
    {
        protected override void ShowPage()
        {
            base.ShowPage();

            if (IsPost)
            {
                DoPost();
            }
            else
            {

            }
        }

        protected void DoPost()
        {
            string trmname = RequestTools.GetFormString("trmname");
            string trmintro = RequestTools.GetFormString("trmintro");
            string trmdesp = RequestTools.GetFormString("trmdesp");
            if (trmname == "" || trmname.Length < 2)
            {
                AddErrLine("治疗名称长度不能小于 2 ");
            }
            if (trmintro == "" || trmintro.Length < 2)
            {
                AddErrLine("治疗简介长度不能小于 2 ");
            }
            if (trmdesp == "" || trmdesp.Length < 2)
            {
                AddErrLine("治疗描述长度不能小于 2 ");
            }
            if (this.ErrorCount > 0)
            {
                this.SetShowBackLink(true);
                return;
            }

            TreatmentInfo info = new TreatmentInfo();
            info.Name = trmname;
            info.Intro = trmintro;
            info.Desp = trmdesp;
            info.PinYin = Chinese.GetPingYinFirstLetter(info.Name);
            info.Type = 1;
            info.UpdateTime = DateTime.Now;
            TreatmentBLL.Instance.AddTreatment(info);
            this.AddMsgLine("治疗添加成功");
            this.SetUrl("ListTreatments.aspx");
            this.SetMetaRefresh(2, "ListTreatments.aspx");

        }
    }
}
